package top.abrsm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import top.abrsm.entity.FileEntity;
import top.abrsm.mapper.FileMapper;
import top.abrsm.service.IFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.abrsm.util.StateEnum;
import top.abrsm.util.StateException;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author WuZH
 * @since 2023-11-18
 */
@Service
public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntity> implements IFileService {


    @Override
    public List<FileEntity> queryList ( FileEntity fileEntity ) {
        if ( fileEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        QueryWrapper<FileEntity> queryWrapper = new QueryWrapper<> ();
        if ( StringUtils.isNotBlank ( fileEntity.getId () ) ) {
            queryWrapper.eq ( "id", fileEntity.getId () );
        }
        if ( StringUtils.isNotBlank ( fileEntity.getFileJoinId () ) ) {
            queryWrapper.eq ( "fileJoinId", fileEntity.getFileJoinId () );
        }
        List<FileEntity> fileEntities = baseMapper.selectList ( queryWrapper );
        return fileEntities;
    }
}
